package com.swiot.biz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.swiot.common.annotation.Log;
import com.swiot.common.core.controller.BaseController;
import com.swiot.common.core.domain.AjaxResult;
import com.swiot.common.enums.BusinessType;
import com.swiot.biz.domain.Segment;
import com.swiot.biz.service.ISegmentService;
import com.swiot.common.utils.poi.ExcelUtil;
import com.swiot.common.core.page.TableDataInfo;

/**
 * 业务板块Controller
 * 
 * @author kingdom
 * @date 2025-09-04
 */
@RestController
@RequestMapping("/biz/segment")
public class SegmentController extends BaseController
{
    @Autowired
    private ISegmentService segmentService;

    /**
     * 查询业务板块列表
     */
    @PreAuthorize("@ss.hasPermi('biz:segment:list')")
    @GetMapping("/list")
    public TableDataInfo list(Segment segment)
    {
        startPage();
        List<Segment> list = segmentService.selectSegmentList(segment);
        return getDataTable(list);
    }

    /**
     * 导出业务板块列表
     */
    @PreAuthorize("@ss.hasPermi('biz:segment:export')")
    @Log(title = "业务板块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Segment segment)
    {
        List<Segment> list = segmentService.selectSegmentList(segment);
        ExcelUtil<Segment> util = new ExcelUtil<Segment>(Segment.class);
        util.exportExcel(response, list, "业务板块数据");
    }

    /**
     * 获取业务板块详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:segment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(segmentService.selectSegmentById(id));
    }

    /**
     * 新增业务板块
     */
    @PreAuthorize("@ss.hasPermi('biz:segment:add')")
    @Log(title = "业务板块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Segment segment)
    {
        return toAjax(segmentService.insertSegment(segment));
    }

    /**
     * 修改业务板块
     */
    @PreAuthorize("@ss.hasPermi('biz:segment:edit')")
    @Log(title = "业务板块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Segment segment)
    {
        return toAjax(segmentService.updateSegment(segment));
    }

    /**
     * 删除业务板块
     */
    @PreAuthorize("@ss.hasPermi('biz:segment:remove')")
    @Log(title = "业务板块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(segmentService.deleteSegmentByIds(ids));
    }
}
